@using UI.Models
@model UI.Models.AddPlayerToGameDisplay
@{
    ViewBag.Title = "Add Player";
}

<h2>Add Player</h2>

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Game</legend>

        @Html.HiddenFor(model => model.GameToDisplay.GameId)
        <br />
        <div class="display-field">@Html.DisplayFor(model => model.Error)</div>
        <br />
        <div class="display-label">Game Id</div>
        <div class="display-field">@Html.DisplayFor(model => model.GameToDisplay.GameId)</div>

        <div class="display-label">Game Date</div>
        <div class="display-field">@Html.DisplayFor(model => model.GameToDisplay.GameDate)</div>

        <div class="display-label">Game Time</div>
        <div class="display-field">@Html.DisplayFor(model => model.GameToDisplay.GameTime)</div>

        <div class="display-label">Status</div>
        <div class="display-field">@Html.DisplayFor(model => model.GameToDisplay.GameStatus)</div>

        <div class="display-label">Currently Playing</div>
        <div class="display-field">@(Model.GameToDisplay.Playing == null ? "None" : Model.GameToDisplay.Playing.Count.ToString())

            <table>
                <tr>
                    <th>Name
                    </th>
                </tr>

                @foreach (var item in Model.GameToDisplay.Playing)
                {
                    <tr>
                        <td>
                            @Html.DisplayTextFor(_ => item.Name)
                        </td>
                    </tr>
                }
            </table>
        </div>

        <div class="display-label">Currently Substituting</div>
        <div class="display-field">@(Model.GameToDisplay.Playing == null ? "None" : Model.GameToDisplay.Substitutions.Count.ToString())

            <table>
                <tr>
                    <th>Name
                    </th>
                </tr>

                @foreach (var item in Model.GameToDisplay.Substitutions)
                {
                    <tr>
                        <td>
                            @Html.DisplayTextFor(_ => item.Name)
                        </td>
                    </tr>
                }
            </table>
        </div>
        @if (Model != null && Model.GameToDisplay.GameStatus.Equals(Domain.GameStatus.Published.ToString()))
        {
            <div class="editor-label">
                @Html.LabelFor(model => model.SelectedPlayer)
            </div>
            <div class="editor-field">
                @Html.ListBoxFor(model => model.SelectedPlayer, UI.Models.Lists.GetAllPlayers())
            </div>
        }
        <p>
            @if (Model != null && Model.GameToDisplay.GameStatus.Equals(Domain.GameStatus.Created.ToString()))
            {
                @Html.ActionLink("Publish Game", "Publish", new { id = Model.GameToDisplay.GameId }) 
            }
            @if (Model != null && Model.GameToDisplay.GameStatus.Equals(Domain.GameStatus.Published.ToString()))
            {
                <input type="submit" value="Add Player" />
            }
            @Html.ActionLink("Back to List", "Index")
        </p>
    </fieldset>
}